package org.docmanagement.commons.struts;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.docmanagement.commons.service.ServiceLocator;

/**
 * @author eveno
 *
 */
public class InitPlugin implements PlugIn {

	/**
	 * 
	 */
	public InitPlugin() {
		super();
	}

	public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
		try {
			initSpring(servlet, config);
		} catch (InitException e) {
			throw new ServletException("Erreur d'initialisation", e);
		}
	}

	private void initSpring(ActionServlet servlet, ModuleConfig config) throws InitException
	{
		Logger.getLogger(getClass()).info("Initialisation de Spring");
	    try
	    {
			ServiceLocator.init(servlet, config);
	    }
	    catch (Exception e)
	    {
	    	Logger.getLogger(getClass()).error("Impossible d'initialiser Spring", e);
	    	throw new InitException("Impossible d'initialiser Spring", e);
	    }
	}

	public void destroy()
	{
		
	}
}
